package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ItemCatalog;
import cn.wolfcode.trip.base.mapper.ItemCatalogMapper;
import cn.wolfcode.trip.base.query.ItemCatalogQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IItemCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ItemCatalogServiceImpl implements IItemCatalogService {
    @Autowired
    private ItemCatalogMapper itemCatalogMapper;

    @Override
    public void delete(Long id) {
        itemCatalogMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<ItemCatalog> selectAll() {
        return itemCatalogMapper.selectAll();
    }

    @Override
    public PageInfo query(ItemCatalogQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ItemCatalog> list = itemCatalogMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(ItemCatalog itemCatalog) {
        if(itemCatalog.getId() == null){
            itemCatalogMapper.insert(itemCatalog);
        }else {
            itemCatalogMapper.updateByPrimaryKey(itemCatalog);
        }
    }


    @Override
    public ItemCatalog get(Long id) {
        return itemCatalogMapper.selectByPrimaryKey(id);
    }

}
